{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2b33ae2-f1c7-48e3-bddc-0d9a65b24946",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "079fc179-c2e4-45dd-9692-a902d6479b73",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'geopy'",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mModuleNotFoundError\u001b[39m                       Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m      1\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpandas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpd\u001b[39;00m\n\u001b[32m      2\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnumpy\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mnp\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgeopy\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mdistance\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m geodesic\n\u001b[32m      4\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01msklearn\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mcluster\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m KMeans\n\u001b[32m      5\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01msklearn\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mensemble\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m RandomForestRegressor\n",
      "\u001b[31mModuleNotFoundError\u001b[39m: No module named 'geopy'"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from geopy.distance import geodesic\n",
    "from sklearn.cluster import KMeans\n",
    "from sklearn.ensemble import RandomForestRegressor\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import mean_squared_error\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "from datetime import datetime, timedelta\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ada7c9dd-f56e-44ab-8d45-6b2a721d825d",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "\n",
    "# 设置绘图风格\n",
    "sns.set(style=\"whitegrid\")\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']  # 用于显示中文\n",
    "plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题\n",
    "\n",
    "# ========== 数据模拟 ==========\n",
    "print(\"🚚 模拟商用车队行驶数据...\")\n",
    "np.random.seed(42)\n",
    "n_vehicles = 500\n",
    "n_days = 90\n",
    "records_per_vehicle = 2000\n",
    "\n",
    "# 模拟车辆基础信息\n",
    "vehicles = pd.DataFrame({\n",
    "    \"vehicle_id\": np.arange(n_vehicles),\n",
    "    \"vehicle_type\": np.random.choice([\"牵引车\", \"厢式货车\", \"冷藏车\", \"自卸车\"], n_vehicles),\n",
    "    \"age\": np.random.randint(1, 10, n_vehicles),\n",
    "    \"load_capacity\": np.random.uniform(5, 30, n_vehicles),\n",
    "    \"insurance_premium\": np.random.uniform(8000, 20000, n_vehicles),\n",
    "    \"claim_history\": np.random.poisson(0.5, n_vehicles)\n",
    "})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc8c2942-8e61-4d82-8913-62bb1f41b639",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# 模拟行驶数据\n",
    "data = pd.DataFrame({\n",
    "    \"vehicle_id\": np.random.choice(np.arange(n_vehicles), records_per_vehicle),\n",
    "    \"timestamp\": pd.to_datetime(np.random.uniform(\n",
    "        datetime(2023, 1, 1).timestamp(),\n",
    "        datetime(2023, 4, 1).timestamp(),\n",
    "        records_per_vehicle\n",
    "    ), unit='s'),\n",
    "    \"speed\": np.clip(np.random.normal(65, 20, records_per_vehicle), 0, 120),\n",
    "    \"acceleration\": np.random.normal(0, 1.5, records_per_vehicle),\n",
    "    \"braking\": np.random.exponential(0.3, records_per_vehicle),\n",
    "    \"engine_load\": np.random.uniform(20, 100, records_per_vehicle),\n",
    "    \"fuel_rate\": np.random.uniform(25, 45, records_per_vehicle),\n",
    "    \"latitude\": np.random.uniform(39.8, 40.0, records_per_vehicle),\n",
    "    \"longitude\": np.random.uniform(116.3, 116.5, records_per_vehicle),\n",
    "    \"road_condition\": np.random.choice([\"干燥\", \"潮湿\", \"冰雪\"], records_per_vehicle, p=[0.7, 0.2, 0.1])\n",
    "})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a4265c1-bae6-4b4d-9867-5405fe2d964c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ea90e09-9d37-4745-90ef-0198736f7c34",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d0b1aa8b-9859-4519-9512-78537b95fcc0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
